package cn.stylefeng.guns.modular.system.controller;

import cn.stylefeng.roses.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import cn.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import cn.stylefeng.guns.modular.system.model.BusinessExtProperty;
import cn.stylefeng.guns.modular.system.service.IBusinessExtPropertyService;

/**
 * 商家信息控制器
 *
 * @author fengshuonan
 * @Date 2019-10-23 18:32:38
 */
@Controller
@RequestMapping("/businessExtProperty")
public class BusinessExtPropertyController extends BaseController {

    private String PREFIX = "/system/businessExtProperty/";

    @Autowired
    private IBusinessExtPropertyService businessExtPropertyService;

    /**
     * 跳转到商家信息首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "businessExtProperty.html";
    }

    /**
     * 跳转到添加商家信息
     */
    @RequestMapping("/businessExtProperty_add")
    public String businessExtPropertyAdd() {
        return PREFIX + "businessExtProperty_add.html";
    }

    /**
     * 跳转到修改商家信息
     */
    @RequestMapping("/businessExtProperty_update/{businessExtPropertyId}")
    public String businessExtPropertyUpdate(@PathVariable Integer businessExtPropertyId, Model model) {
        BusinessExtProperty businessExtProperty = businessExtPropertyService.selectById(businessExtPropertyId);
        model.addAttribute("item",businessExtProperty);
        LogObjectHolder.me().set(businessExtProperty);
        return PREFIX + "businessExtProperty_edit.html";
    }

    /**
     * 获取商家信息列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {
        return businessExtPropertyService.selectList(null);
    }

    /**
     * 新增商家信息
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(BusinessExtProperty businessExtProperty) {
        businessExtPropertyService.insert(businessExtProperty);
        return SUCCESS_TIP;
    }

    /**
     * 删除商家信息
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer businessExtPropertyId) {
        businessExtPropertyService.deleteById(businessExtPropertyId);
        return SUCCESS_TIP;
    }

    /**
     * 修改商家信息
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(BusinessExtProperty businessExtProperty) {
        businessExtPropertyService.updateById(businessExtProperty);
        return SUCCESS_TIP;
    }

    /**
     * 商家信息详情
     */
    @RequestMapping(value = "/detail/{businessExtPropertyId}")
    @ResponseBody
    public Object detail(@PathVariable("businessExtPropertyId") Integer businessExtPropertyId) {
        return businessExtPropertyService.selectById(businessExtPropertyId);
    }
}
